<?php
namespace Admin\Controller;
use Think\Controller;
use think\Page;
class OrderManageController extends Controller
{
     public function __construct()
     {
         parent::__construct();
         if(!logAdmin(session('adminId'))) header('location:'.U('Admin/Index/login'));
     }

    public function index(){
         
     }
     
     public function Order_list(){
         if(IS_GET){
         $type= array();
         $type=explode(',',I('get.type'));
         $type=empty($type)?array(1):$type;
         $result=D('Order')->Order_List($type);
         $money=D('Order')->Count_money($type);
         $this->assign('money',$money);
         $this->assign('order_type',$type[0]);
         $this->assign('Order_List',$result['list']);
         $this->assign('page',$result['show']);
         $len=count($type);
         switch ($len){
             case 2: 
                 if($type[0]==1){
                 $this->display('OrderManage/BookOrder_list'); 
                 }                //显示书籍订单列表页面
                 else  $this->display('OrderManage/OtherOrder_list'); break;   //显示电子资料、题库、押密流水列表页面            
            default:
                 $this->display('OrderManage/AllOrder_list');                 //显示全部列表页面
         }
     }
     }  
     
     public function Edit_status(){
         if(IS_GET){
             $order_id=I('get.order_id');            
             if($order_id!=''){
                  $status=D('Order')->Edit_status($order_id);
                  $this->assign('order_id',$status['order_id']);
                  $this->assign('status',$status['status']);
                  $this->display('OrderManage/Edit_status');
             }
         }
     }
     
     public function save_status(){
         if(IS_POST){
             $status=I('post.');
             if(!empty($status)){
                  $result=D('Order')->save_status($status);
                  $result=$result?'修改成功':'修改失败';
                  $this->ajaxReturn($result);
             }else{
                  $this->ajaxReturn('提交信息出错');
             }
         }
     }
     
     public function Delete_order(){
         if(IS_POST){
             $info=I('post.');
             if(!empty($info)){
                 $result=D('Order')->delete_order($info);
                 $dele=$result['delCount']?true:false;
                 $money=$result['money'];
                 $data['delCount']=$dele;
                 $data['money']=$money;
                 $this->ajaxReturn($data);
             }else{
                 $this->ajaxReturn('提交信息出错');
             }
         }
     }
     
     public function Delete_all(){
         if(IS_POST){
             $info=I('post.');
             if(!empty($info)){
                 $type=explode(',',$info['order_type']);
                 $result=D('Order')->delete_all($info);
                 $dele=$result['delCount']?true:false;
                 $money=$result['money'];
                 $data['delCount']=$dele;
                 $data['money']=$money;
                 $this->ajaxReturn($data);
             }else{
                 $this->ajaxReturn('提交信息出错');
             }
         }
     }
     
     /*
      * 进行订单的筛选查询，order_type为订单类型。数据库中默认的订单日期为 2000-01-01的时间戳
      */
     
     public function query_order(){
          if(IS_GET){
              $data=I('get.');
              if(!empty($data)){                      
                       $list=D('Order')->query_order($data);                    
                  if($list['list']){
                       $this->assign('page',$list['show']);
                       $this->assign('money',$list['money']);
                       $this->assign('Order_List',$list['list']);
                       $this->assign('order_type',$data['order_type']);
                       switch($data['order_type']){
                           case 1:
                                 $this->display('OrderManage/BookOrder_list');break;
                           case 2:
                                $this->display('OrderManage/OtherOrder_list');break;
                           case 3:
                                 $this->display('OrderManage/OtherOrder_list');break;
                           case 4:
                                 $this->display('OrderManage/OtherOrder_list');break;
                           default:  
                                 $this->display('OrderManage/AllOrder_list');
                       }
                   
                   }
                   else{
                       $this->error('未查找到满足条件的数据');
                   }
              }
          }
     }
}